//
//  NewsViewController.m
//  LOL_JewelBox
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 dllo. All rights reserved.
//


#import "NewsViewController.h"
//滚动图片
#import "SDCycleScrollView.h"
#import "AFHTTPRequestOperationManager.h"
//菜单抽屉
#import "RNFrostedSidebar.h"
//滚动条
#import "HMSegmentedControl.h"
#import "NewsView.h"
#import "NewsModel.h"
#import "CompetitionModel.h"
#import "ScrollPictureModel.h"
#import "NewsCell.h"
#import "CompetitionCell.h"
#import "MJRefresh.h"
#import "DetailNewsViewController.h"
#import "DetailCompetitionViewController.h"
#import "ScrollPictureDetailModel.h"
#import "DetailPictureViewController.h"
#import "LolPictureModel.h"
#import "LoLPictureCell.h"
#import "UIImageView+WebCache.h"
#import "DetailLolPictureViewController.h"
#import "BelleCell.h"
#import "belleModel.h"
#import "DetailBelleViewController.h"
#import "DetailPostViewController.h"
#import "CollectViewController.h"
#import "UserViewController.h"
#import "CombatViewController.h"
#import "OursViewController.h"
@interface NewsViewController ()<SDCycleScrollViewDelegate,RNFrostedSidebarDelegate>
@property(nonatomic, retain)NSMutableArray *scrollArr;
@property(nonatomic,retain)NSMutableArray *pictureArr;
@property(nonatomic, retain)NSMutableArray *newsArr;
@property(nonatomic,retain)NSMutableArray *CompetitionArr;
@property(nonatomic,retain)NSMutableArray *transformArr;
@property(nonatomic,retain)NSMutableArray *detailPictureArr;
@property(nonatomic, retain)SDCycleScrollView *cycleScrollView;
@property(nonatomic, retain)UITableView *tableView;
@property(nonatomic, assign)NSInteger newsNum;
@property(nonatomic, assign)NSInteger CompetitionNum;
@property(nonatomic, assign)NSInteger belleNum;
@property(nonatomic, assign)NSInteger LoLPictureNum;
@property(nonatomic, assign)NSInteger postNum;
@property(nonatomic, retain)NSMutableArray *LoLPictureArr;
@property(nonatomic, retain)NSMutableArray *belleArr;
@property(nonatomic,retain)NSMutableArray *postArr;
@property(nonatomic,retain)HMSegmentedControl *segmentedControl;
// 抽屉效果
@property (nonatomic, strong) NSMutableIndexSet *optionIndices;
@property(nonatomic, retain)UIImageView *picImageView;



@end

@implementation NewsViewController


- (void)dealloc
{
    [_scrollArr release];
    [_cycleScrollView release];
    [_pictureArr release];
    [_CompetitionArr release];
    [_transformArr release];
    [_detailPictureArr release];
    [_LoLPictureArr release];
    [_belleArr release];
    [_picImageView release];
    [super dealloc];
}

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.scrollArr = [NSMutableArray array];
        self.pictureArr = [NSMutableArray array];
        self.newsArr = [NSMutableArray array];
        self.CompetitionArr = [NSMutableArray array];
        self.transformArr = [NSMutableArray array];
        self.detailPictureArr = [NSMutableArray array];
        self.LoLPictureArr = [NSMutableArray array];
        self.belleArr = [NSMutableArray array];
        self.postArr = [NSMutableArray array];
        self.optionIndices = [NSMutableIndexSet indexSet];
        self.newsNum = 2;
        self.CompetitionNum = 2;
        self.LoLPictureNum= 2;
        self.belleNum = 2;
        self.postNum = 2;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
#pragma mark 滚动图片数据解析
    [self GetJson];
#pragma mark 新闻,赛事,囧图,美女,神贴数据解析
    [self GetNews];
    [self GetCompetition];
    [self GetLoLPicture];
    [self Getbelle];
    [self GetPost];
    // Do any additional setup after loading the view.
    self.view.backgroundColor= [UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:0.99];
    NewsView *newsView = [[NewsView alloc]initWithFrame:CGRectMake(0, 0, VIEWWIDTH, VIEWHEIGHT)];
    [self.view addSubview:newsView];
    newsView.tag = 1000;
    [newsView release];
    
    self.segmentedControl = [[HMSegmentedControl alloc]initWithSectionTitles:@[@"新闻", @"赛事", @"囧图", @"美女", @"神贴"]];
    self.segmentedControl.frame = CGRectMake(0, 0, VIEWWIDTH, (VIEWHEIGHT - 64- 49) *0.05415);
    self.segmentedControl.layer.borderWidth = 0;
    [self.segmentedControl addTarget:self action:@selector(segClick:) forControlEvents:UIControlEventValueChanged];
    [self.segmentedControl setTextColor:[UIColor blackColor]];
//    [self.segmentedControl setSelectionIndicatorColor:[UIColor blueColor]];
    [self.segmentedControl setBackgroundColor:[UIColor colorWithRed:0.98 green:0.98 blue:0.98 alpha:0.98]];
    [newsView addSubview:self.segmentedControl];
    [_segmentedControl release];

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, (VIEWHEIGHT - 64- 49) *0.05415, VIEWWIDTH, (VIEWHEIGHT - 64 -49) *0.94585) style:UITableViewStylePlain];
    [newsView addSubview:self.tableView];
    self.navigationItem.title = @"资讯";
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [_tableView release];
#pragma mark 添加抽屉效果
    [self createDesk];
    
#pragma mark 上拉刷新下拉加载
    [self addHeader];
    [self addFooter];

}

- (void)creatScrollView
{
    
    //网络加载 --- 创建带标题的图片轮播
    self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0,VIEWHEIGHT *0.05415, VIEWWIDTH, VIEWHEIGHT *0.32491) imageURLsGroup:nil];
//    NSLog(@"%g", VIEWHEIGHT);
    self.cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    self.cycleScrollView.delegate = self;
    // 自定义分页控件小圆标颜色
    self.cycleScrollView.dotColor = [UIColor yellowColor];
    NewsView *newView = (NewsView *)[self.view viewWithTag:1000];
    [newView addSubview:self.cycleScrollView];
    self.cycleScrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Picture"]];
    self.cycleScrollView.autoScrollTimeInterval = 8.0;
    self.tableView.tableHeaderView = self.cycleScrollView;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    });
}
-(void)GetJson
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://lol.zhangyoubao.com/apis/rest/ItemsService/ads?&i_=70CCD531-7601-4F9D-B1E8-130796BF8400&t_=1429269740&p_=31565&v_=40040306&d_=ios&osv_=8.3&version=0&a_=lol" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"data"];
        
        for (NSMutableDictionary *dic in arr) {
            ScrollPictureModel *scrModel = [[ScrollPictureModel alloc]init];
            [scrModel setValuesForKeysWithDictionary:dic];
            NSURL *url = [NSURL URLWithString:scrModel.pic_ad_url];
            
            [self.pictureArr addObject:url];
            [scrModel release];
        }
        [self creatScrollView];
        
        self.cycleScrollView.imageURLsGroup = self.pictureArr;
//        [self.cycleScrollView layoutSubviews];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"网络请求有误");
    }];
    
    AFHTTPRequestOperationManager *manager1 = [AFHTTPRequestOperationManager manager];
    [manager1 GET:@"http://lol.zhangyoubao.com/apis/rest/ItemsService/ads?&i_=70CCD531-7601-4F9D-B1E8-130796BF8400&t_=1429269740&p_=31565&v_=40040306&d_=ios&osv_=8.3&version=0&a_=lol" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"data"];
        for (NSMutableDictionary *dic in arr) {
            ScrollPictureDetailModel *model = [[ScrollPictureDetailModel alloc]init];
            model.itemid = dic[@"goto_param"][@"itemid"];
            [self.detailPictureArr addObject:model.itemid];
            [model release];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"网络请求有误");
    }];
    
}

- (void)createDesk
{

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"菜单" style:UIBarButtonItemStylePlain target:self action:@selector(deskAction:)];

}
// deskAction 抽屉效果
- (void)deskAction:(id)sender
{
    NSArray *images = @[[UIImage imageNamed:@"战斗力"],[UIImage imageNamed:@"设置"],[UIImage imageNamed:@"收藏"],[UIImage imageNamed:@"关于我们"]];

    NSArray *colors = @[[UIColor colorWithRed:240/255.f green:159/255.f blue:254/255.f alpha:1],
                        [UIColor colorWithRed:255/255.f green:137/255.f blue:167/255.f alpha:1],
                        [UIColor colorWithRed:126/255.f green:242/255.f blue:195/255.f alpha:1],
                        [UIColor colorWithRed:119/255.f green:152/255.f blue:255/255.f alpha:1]];


    RNFrostedSidebar *callout = [[RNFrostedSidebar alloc] initWithImages:images selectedIndices:self.optionIndices borderColors:colors];
    callout.borderWidth = 5;
    callout.delegate = self;
    [callout show];
}
#pragma mark 抽屉效果点击事件
- (void)sidebar:(RNFrostedSidebar *)sidebar didTapItemAtIndex:(NSUInteger)index
{
    if (index == 0) {
        CombatViewController *combat = [[CombatViewController alloc] init];
        [self.navigationController pushViewController:combat animated:YES];
        [combat release];
        [sidebar dismiss];
    }

    if (index == 1) {
        UserViewController *userView = [[UserViewController alloc]init];
        [self.navigationController pushViewController:userView animated:YES];
        [userView release];
        self.tabBarController.tabBar.hidden = YES;
        [sidebar dismiss];
    }
    else if (index == 2) {
       CollectViewController *collectView = [[CollectViewController alloc]init];
        [self.navigationController pushViewController:collectView animated:YES];
        [collectView release];
        self.tabBarController.tabBar.hidden = YES;
        [sidebar dismiss];
    }


    if (index == 3) {
        OursViewController *our = [[OursViewController alloc] init];
        [self.navigationController pushViewController:our animated:YES];
        [our release];
        [sidebar dismiss];
    }
}
- (void)sidebar:(RNFrostedSidebar *)sidebar didEnable:(BOOL)itemEnabled itemAtIndex:(NSUInteger)index {
    if (itemEnabled) {
        [self.optionIndices addIndex:index];
    }
    else {
        [self.optionIndices removeIndex:index];
    }
}



-(void)addHeader{
   
    [self.tableView  addHeaderWithCallback:^{
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 *NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [self.tableView reloadData];
            [self.tableView headerEndRefreshing];
        });
    }];
 [self.tableView headerBeginRefreshing];
}

-(void)addFooter{
    
    [self.tableView addFooterWithCallback:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 *  NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            if (self.segmentedControl.selectedIndex == 0) {
                AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
                [manager GET:[NSString stringWithFormat:@"http://lol.zhangyoubao.com/apis/rest/ItemsService/lists?cattype=news&catid=10000&page=%ld&i_=70CCD531-7601-4F9D-B1E8-130796BF8400&t_=1429269740&p_=31565&v_=40040306&d_=ios&osv_=8.3&version=0&a_=lol", self.newsNum] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
                    NSMutableDictionary *dic = responseObject;
                    NSMutableArray *arr = dic[@"data"];
                    for (NSMutableDictionary *dic in arr) {
                        NewsModel *newsMo = [[NewsModel alloc]init];
                        [newsMo setValuesForKeysWithDictionary:dic];
                        [self.transformArr addObject: newsMo];
//                        [self.newsArr addObject:newsMo];
                        [newsMo release];
                    }
                    self.newsNum++;
                    [self.tableView reloadData];
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                    
                }];


            }else if (self.segmentedControl.selectedIndex == 1)
            {
                AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
                [manager GET:[NSString stringWithFormat:@"http://lol.zhangyoubao.com/apis/rest/ItemsService/lists?cattype=news&catid=10006&page=%ld&i_=70CCD531-7601-4F9D-B1E8-130796BF8400&t_=1429269740&p_=31565&v_=40040306&d_=ios&osv_=8.3&version=0&a_=lol",self.CompetitionNum] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
                    NSMutableDictionary *dic = responseObject;
                    NSMutableArray *arr = dic[@"data"];
                    for (NSMutableDictionary *dic in arr) {
                        CompetitionModel *comMo = [[CompetitionModel alloc]init];
                        [comMo setValuesForKeysWithDictionary:dic];
                        [self.transformArr addObject:comMo];
//                        [self.CompetitionArr addObject:comMo];
                        [comMo release];
                    }
                    self.CompetitionNum++;
                    [self.tableView reloadData];
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                }];

            }else if (self.segmentedControl.selectedIndex == 2)
            {
                AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
                [manager GET:[NSString stringWithFormat:@"http://lol.data.shiwan.com/getArticleListImprove/?cid_rel=213&page=%ld", self.LoLPictureNum] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
                    NSMutableDictionary *dic =responseObject;
                    NSMutableArray *arr = dic[@"result"];
                    for (NSMutableDictionary *dic  in arr) {
                        LolPictureModel *LolPicMo = [[LolPictureModel alloc]init];
                        [LolPicMo setValuesForKeysWithDictionary:dic];
                        [self.transformArr addObject:LolPicMo];
//                        [self.LoLPictureArr addObject:LolPicMo];
                        [LolPicMo release];
                    }
                    self.LoLPictureNum++;
                    [self.tableView reloadData];
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                    
                }];

                
            }else if (self.segmentedControl.selectedIndex == 3)
            {
                AFHTTPRequestOperationManager *manager3 = [AFHTTPRequestOperationManager manager];
                [manager3 GET:[NSString stringWithFormat:@"http://lol.data.shiwan.com/getArticleListImprove/?cid_rel=210&page=%ld", self.belleNum] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
                    NSMutableDictionary *dic = responseObject;
                    NSMutableArray *arr = dic[@"result"];
                    for (NSMutableDictionary  *dic in arr) {
                        belleModel *beMO = [[belleModel alloc]init];
                        [beMO setValuesForKeysWithDictionary:dic];
                        [self.transformArr addObject:beMO];
                        [beMO release];
                    }
                    self.belleNum++;
                    [self.tableView reloadData];
                    
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                    
                }];

            }
            else if (self.segmentedControl.selectedIndex == 4)
            {
                AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
                [manager GET:[NSString stringWithFormat:@"http://lol.data.shiwan.com/getArticleListImprove/?cid_rel=212&page=%ld", self.
                              postNum] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
                    NSMutableDictionary *dic = responseObject;
                    NSMutableArray *arr = dic[@"result"];
                    for (NSMutableDictionary  *dic in arr) {
                        LolPictureModel *lolModel = [[LolPictureModel alloc]init];
                        [lolModel setValuesForKeysWithDictionary:dic];
                        [self.transformArr addObject:lolModel ];
                        [lolModel  release];
                    }
                    self.postNum++;
                    [self.tableView reloadData];
                    
                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                    
                }];

            }
//            [self.tableView reloadData];
            [self.tableView footerEndRefreshing];
        });
    }];
}

-(void)GetNews
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://lol.zhangyoubao.com/apis/rest/ItemsService/lists?cattype=news&catid=10000&page=1&i_=70CCD531-7601-4F9D-B1E8-130796BF8400&t_=1429269740&p_=31565&v_=40040306&d_=ios&osv_=8.3&version=0&a_=lol" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"data"];
        for (NSMutableDictionary *dic in arr) {
            NewsModel *newsMo = [[NewsModel alloc]init];
            [newsMo setValuesForKeysWithDictionary:dic];
            [self.newsArr addObject: newsMo];
            [newsMo release];
        }
        self.segmentedControl.selectedIndex = 0;
        [self segClick:self.segmentedControl];
        [self.tableView reloadData];
        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];
}
-(void)GetCompetition{

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://lol.zhangyoubao.com/apis/rest/ItemsService/lists?cattype=news&catid=10006&page=1&i_=70CCD531-7601-4F9D-B1E8-130796BF8400&t_=1429269740&p_=31565&v_=40040306&d_=ios&osv_=8.3&version=0&a_=lol" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"data"];
        for (NSMutableDictionary *dic in arr) {
            CompetitionModel *comMo = [[CompetitionModel alloc]init];
            [comMo setValuesForKeysWithDictionary:dic];
            [self.CompetitionArr addObject:comMo];
            [comMo release];
        }
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];
}

-(void)GetLoLPicture{

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://lol.data.shiwan.com/getArticleListImprove/?cid_rel=213&page=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic =responseObject;
        NSMutableArray *arr = dic[@"result"];
        for (NSMutableDictionary *dic  in arr) {
            LolPictureModel *LolPicMo = [[LolPictureModel alloc]init];
            [LolPicMo setValuesForKeysWithDictionary:dic];
            [self.LoLPictureArr addObject:LolPicMo];
            [LolPicMo release];
        }
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];
}
-(void)Getbelle{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://lol.data.shiwan.com/getArticleListImprove/?cid_rel=210&page=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"result"];
        for (NSMutableDictionary  *dic in arr) {
            belleModel *beMO = [[belleModel alloc]init];
            [beMO setValuesForKeysWithDictionary:dic];
            [self.belleArr addObject:beMO];
            [beMO release];
        }
        [self.tableView reloadData];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];
}
-(void)GetPost{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager GET:@"http://lol.data.shiwan.com/getArticleListImprove/?cid_rel=212&page=1" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSMutableDictionary *dic = responseObject;
        NSMutableArray *arr = dic[@"result"];
        for (NSMutableDictionary  *dic in arr) {
            LolPictureModel *lolModel = [[LolPictureModel alloc]init];
            [lolModel setValuesForKeysWithDictionary:dic];
            [self.postArr addObject:lolModel ];
            [lolModel  release];
        }
        [self.tableView reloadData];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.transformArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger index = self.segmentedControl.selectedIndex;
    if (index == 0) {
        static NSString *resue = @"resue";
        NewsCell *cell = [tableView dequeueReusableCellWithIdentifier:resue];
        if (cell == nil) {
            cell = [[[NewsCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:resue]autorelease];
        }
        NewsModel *newsMo = self.transformArr[indexPath.row];
        cell.titleLabel.text = newsMo.title;
        cell.descLabel.text = newsMo.desc;
        cell.selectionStyle = NO;
        return cell;
    }else if (index == 1)
    {
        static NSString *lala = @"lala";
        CompetitionCell *cell = [tableView dequeueReusableCellWithIdentifier:lala];
        if (cell == nil) {
            cell = [[[CompetitionCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:lala]autorelease];
        }
        CompetitionModel *comMo = self.transformArr[indexPath.row];
        cell.titleLabel.text = comMo.title;
        cell.descLabel.text = comMo.desc;
         cell.selectionStyle = NO;
        return cell;
    }
    else if (index == 2)
    {
        static NSString *We = @"We";
        LoLPictureCell *cell = [tableView dequeueReusableCellWithIdentifier:We];
        if (cell == nil) {
            cell = [[[LoLPictureCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:We]autorelease];
        }
        LolPictureModel *LolPicMo = self.transformArr[indexPath.row];
        NSURL *url = [NSURL URLWithString:LolPicMo.icon];
        [cell.iconImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        
        cell.titleLabel.text = LolPicMo.title;
        cell.shortLabel.text = LolPicMo.Oshort;
         cell.selectionStyle = NO;
        return cell;
    }
    else if (index == 3)
    {
        static NSString *jj = @"jj";
        BelleCell *cell = [tableView dequeueReusableCellWithIdentifier:jj];
        if (cell == nil) {
            cell = [[[BelleCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:jj]autorelease];
        }
        belleModel *beMo = self.transformArr[indexPath.row];
        NSURL *url = [NSURL URLWithString:beMo.icon];
        [cell.iconImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        cell.titleLabel.text = beMo.title;
        cell.shortLabel.text = beMo.Oshort;
         cell.selectionStyle = NO;
        return cell;
    }
    else if (index == 4)
    {
        static NSString *cc = @"cc";
        BelleCell *cell = [tableView dequeueReusableCellWithIdentifier:cc];
        if (cell == nil) {
            cell = [[[BelleCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cc]autorelease];
        }
        LolPictureModel *LolMo = self.transformArr[indexPath.row];
        NSURL *url = [NSURL URLWithString:LolMo.icon];
        [cell.iconImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"占位图"]];
        cell.titleLabel.text = LolMo.title;
        cell.shortLabel.text = LolMo.Oshort;
         cell.selectionStyle = NO;
        return cell;
    }
    else{
        return nil;
    }
}



-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    DetailPictureViewController *DPVC = [[DetailPictureViewController alloc]init];
    [self.navigationController pushViewController:DPVC animated:YES];
    NSString *model = self.detailPictureArr[index];

    DPVC.item = model;

    [DPVC release];
}

-(void)segClick:(HMSegmentedControl *)click
{
    [self.transformArr removeAllObjects];
    NSInteger index = click.selectedIndex;
    if (index == 0) {
        
        for (NewsModel *temp in self.newsArr) {
            [self.transformArr addObject:temp];
        }

        [self.tableView reloadData];
    }
    else if (index == 1)
    {
        for (CompetitionModel *temp in self.CompetitionArr) {
            [self.transformArr addObject:temp];
        }

        [self.tableView reloadData];
    }else if (index == 2)
    {
        for (LolPictureModel *temp in self.LoLPictureArr) {
            [self.transformArr addObject:temp];
        }

        [self.tableView reloadData];
    }else if (index == 3)
    {
        for (belleModel *temp in self.belleArr) {
            [self.transformArr addObject:temp];
        }

        [self.tableView reloadData];
    }else if (index == 4)
    {
        for (LolPictureModel *temp in self.postArr) {
            [self.transformArr addObject:temp];
        }
        [self.tableView reloadData];
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger index = self.segmentedControl.selectedIndex;
    if (index == 0) {
        DetailNewsViewController *detailNew = [[DetailNewsViewController alloc]init];
        [self.navigationController pushViewController:detailNew animated:YES];
        NewsModel *newsMo = self.transformArr[indexPath .row];
        detailNew.id = newsMo.id;
        detailNew.title = newsMo.title;
        [detailNew release];
    }else if (index == 1){
        DetailCompetitionViewController *detailCom = [[DetailCompetitionViewController alloc]init];
        [self.navigationController pushViewController:detailCom animated:YES];
        CompetitionModel *comMo = self.transformArr[indexPath.row];
        detailCom.id = comMo.id;
        detailCom.title = comMo.title;
        [detailCom release];
    }else if (index == 2){
        DetailLolPictureViewController *detailLol = [[DetailLolPictureViewController alloc]init];
        [self.navigationController pushViewController:detailLol animated:YES];
        LolPictureModel *LolMo = self.transformArr[indexPath.row];
        detailLol.id = LolMo.id;
        detailLol.title = LolMo.title;
        [detailLol release];
    }else if (index == 3){
        DetailBelleViewController *detailbelle = [[DetailBelleViewController alloc]init];
        [self.navigationController pushViewController:detailbelle animated:YES];
        belleModel *belleMo = self.transformArr[indexPath.row];
        detailbelle.id = belleMo.id;
        detailbelle.title = belleMo.title;
        [detailbelle release];
    }else if (index == 4){
        DetailPostViewController *detailPost = [[DetailPostViewController alloc]init];
        [self.navigationController pushViewController:detailPost animated:YES];
        LolPictureModel *LolMo = self.transformArr[indexPath.row];
        detailPost.id = LolMo.id;
        detailPost.title = LolMo.title;
        [detailPost release];
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger index = self.segmentedControl.selectedIndex;
    if (index == 0 || index == 1) {
        return VIEWHEIGHT *0.12635;
    }else if (index == 2){
        return VIEWHEIGHT  *0.21661;
    }else
    {
        return  VIEWHEIGHT * 0.21661;
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
